home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Source
/
AutoBin Source
/
DSUserProcs.c
< prev
next >
Wrap
Text File
|
1993-12-09
|
8KB
|
250 lines
/******************************************************************************
**
** Project Name: DropShell
** File Name: DSUserProcs.c
**
** Description: Specific AppleEvent handlers used by the DropBox
**
*******************************************************************************
** A U T H O R I D E N T I T Y
*******************************************************************************
**
** Initials Name
** -------- -----------------------------------------------
** LDR Leonard Rosenthol
** MTC Marshall Clow
** SCS Stephan Somogyi
**
*******************************************************************************
** R E V I S I O N H I S T O R Y
*******************************************************************************
**
** Date Time Author Description
** -------- ----- ------ ---------------------------------------------
** 01/25/92 LDR Removed the use of const on the userDataHandle
** 12/09/91 LDR Added the new SelectFile userProc
** Added the new Install & DisposeUserGlobals procs
** Modified PostFlight to only autoquit on odoc, not pdoc
** 11/24/91 LDR Added the userProcs for pdoc handler
** Cleaned up the placement of braces
** Added the passing of a userDataHandle
** 10/29/91 SCS Changes for THINK C 5
** 10/28/91 LDR Officially renamed DropShell (from QuickShell)
** Added a bunch of comments for clarification
** 10/06/91 00:02 MTC Converted to MPW C
** 04/09/91 00:02 LDR Added to Projector
**
******************************************************************************/
#include "DSGlobals.h"
#include "DSUserProcs.h"
#include "binhex.h"
/*
This routine is called during init time.
It allows you to install more AEVT Handlers beyond the standard four
*/
#pragma segment Main
pascal void InstallOtherEvents (void) {
}
/*
This routine is called when an OAPP event is received.
Currently, all it does is set the gOApped flag, so you know that
you were called initally with no docs, and therefore you shouldn't
quit when done processing any following odocs.
*/
#pragma segment Main
pascal void OpenApp (void) {
gOApped = true;
}
/*
This routine is called when an QUIT event is received.
We simply set the global done flag so that the main event loop can
gracefully exit. We DO NOT call ExitToShell for two reasons:
1) It is a pretty ugly thing to do, but more importantly
2) The Apple event manager will get REAL upset!
*/
#pragma segment Main
pascal void QuitApp (void) {
gDone = true; /* All Done! */
}
/*
This routine is the first one called when an ODOC or PDOC event is received.
In this routine you would place code used to setup structures, etc.
which would be used in a 'for all docs' situation (like "Archive all
dropped files")
Obviously, the opening boolean tells you whether you should be opening
or printing these files based on the type of event recieved.
userDataHandle is a handle that you can create & use to store your own
data structs. This dataHandle will be passed around to the other
odoc/pdoc routines so that you can get at your data without using
globals - just like the new StandardFile.
We also return a boolean to tell the caller if you support this type
of event. By default, our dropboxes don't support the pdoc, so when
opening is FALSE, we return FALSE to let the caller send back the
proper error code to the AEManager.
You will probably want to remove the #pragma unused (currently there to fool the compiler!)
*/
#pragma segment Main
pascal Boolean PreFlightDocs (Boolean opening, Handle *userDataHandle) {
#pragma unused ( userDataHandle )
return opening; // we support opening, but not printing - see above
}
/*
This routine is called for each file passed in the ODOC event.
In this routine you would place code for processing each file/folder/disk that
was dropped on top of you.
You will probably want to remove the #pragma unused (currently there to fool the compiler!)
*/
#pragma segment Main
//--------------------------------------------------------
void CopyPascalString(StringPtr src,StringPtr dst)
//--------------------------------------------------------
{
BlockMove(src,dst,src[0]+1);
}
//--------------------------------------------------------
void CatPascalString(StringPtr dst,StringPtr src)
//--------------------------------------------------------
{
short srclen = src[0],
dstlen = dst[0];
if (srclen + dstlen > 256 )
srclen = (256 - dstlen);
BlockMove(&src[1],&dst[dstlen + 1],srclen);
dstlen +=srclen;
dst[0]=dstlen;
}
pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle ) {
//#pragma unused ( myFSSPtr )
//#pragma unused ( opening )
//#pragma unused ( userDataHandle )
Str255 fileName;
short oe;
extern short gRefNum;
char len;
CopyPascalString(myFSSPtr->name,fileName);
CatPascalString(fileName,"\p.hqx");
HCreate(myFSSPtr->vRefNum,myFSSPtr->parID,fileName,'R*ch','TEXT');
oe = HOpen(myFSSPtr->vRefNum,myFSSPtr->parID,fileName,fsRdWrPerm,&gRefNum);
oe = SetEOF(gRefNum,0); //reset it to 0 if not already
if (oe == noErr) {
SendBinHex(myFSSPtr->vRefNum,myFSSPtr->parID,myFSSPtr->name);
FSClose(gRefNum);
FlushVol(nil,myFSSPtr->vRefNum);
}
}
/*
This routine is the last routine called as part of an ODOC event.
In this routine you would place code to process any structures, etc.
that you setup in the PreflightDocs routine.
If you created a userDataHandle in the PreFlightDocs routines, this is
the place to dispose of it since the Shell will NOT do it for you!
You will probably want to remove the #pragma unusued (currently there to fool the compiler!)
*/
#pragma segment Main
pascal void PostFlightDocs ( Boolean opening, Handle userDataHandle ) {
#pragma unused ( opening )
#pragma unused ( userDataHandle )
if ( (opening) && (!gOApped) )
gDone = true; // close everything up!
/*
The reason we do not auto quit is based on a recommendation in the
Apple event Registry which specifically states that you should NOT
quit on a 'pdoc' as the Finder will send you a 'quit' when it is
ready for you to do so.
*/
}
/*
This routine is called when the user chooses "Select File…" from the
File Menu.
Currently it simply calls the new StandardGetFile routine to have the
user select a single file (any type, numTypes = -1) and then calls the
SendODOCToSelf routine in order to process it.
The reason we send an odoc to ourselves is two fold: 1) it keeps the code
cleaner as all file openings go through the same process, and 2) if events
are ever recordable, the right things happen (this is called Factoring!)
Modification of this routine to only select certain types of files, selection
of multiple files, and/or handling of folder & disk selection is left
as an exercise to the reader.
*/
pascal void SelectFile (void)
{
StandardFileReply stdReply;
SFTypeList theTypeList;
StandardGetFile(NULL, -1, theTypeList, &stdReply);
if (stdReply.sfGood) // user did not cancel
SendODOCToSelf(&stdReply.sfFile); // so send me an event!
}
/*
This routine is called during the program's initialization and gives you
a chance to allocate or initialize any of your own globals that your
dropbox needs.
You return a boolean value which determines if you were successful.
Returning false will cause DropShell to exit immediately.
*/
pascal Boolean InitUserGlobals(void)
{
NewLine[0]=1;
NewLine[1]=13;
NewLine[2]=0;
return(true); // nothing to do, it we must be successful!
}
/*
This routine is called during the program's cleanup and gives you
a chance to deallocate any of your own globals that you allocated
in the above routine.
*/
pascal void DisposeUserGlobals(void)
{
// nothing to do for our sample dropbox
}